﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crosland.Automotriz.Core;
namespace Crosland.Automotriz.Data.Dao.Linq
{
    public class clsTd_Org_VtaDAO
    {

        private AutomotrizEntities ContextoDeObjs = new AutomotrizEntities();

        public List<TD_ORG_VTA> lista()
        {
            List<TD_ORG_VTA> list = new List<TD_ORG_VTA>();
            try
            {
                var q = from o in ContextoDeObjs.TD_ORG_VTA
                        orderby o.DES_ORG_VTA
                        select o;
                list = q.ToList();
            }
            catch
            {
                list = null;
            }
            return list;
        }



        public IEnumerable<Object> lista_organizacion()
        {
            IEnumerable<Object> list = new List<Object>();
            try
            {
                var q = from o in ContextoDeObjs.TD_ORG_VTA
                        orderby o.DES_ORG_VTA
                        select new
                        { ID_ORG_VTA = o.ID_ORG_VTA, COD_ORG_VTA = o.COD_ORG_VTA, DES_ORG_VTA = o.DES_ORG_VTA };
                list = q.ToList();
            }
            catch
            {
                list = null;
            }
            return list;
        }



        public IEnumerable<Object> ListaOrgClienteVendedor()
        {
            IEnumerable<Object> list = new List<Object>();
            try
            {
                var q = from o in ContextoDeObjs.TD_ORG_VTA
                        join c in ContextoDeObjs.T_CLIENTE_VENDEDOR
                        on o.ID_ORG_VTA equals c.ID_ORG_VTA
                        select new
                        {
                            o.ID_ORG_VTA,
                            o.DES_ORG_VTA
                        };
                list = q.OrderByDescending(x => x.DES_ORG_VTA).Distinct().ToList();
            }
            catch (Exception)
            {
                list = null;
            }

            return list;
        }

        public List<TD_ORG_VTA> lista(int? intIdOrgVta)
        {
            List<TD_ORG_VTA> list = new List<TD_ORG_VTA>();

            try
            {
                var q = from o in ContextoDeObjs.TD_ORG_VTA
                        where o.ID_ORG_VTA == intIdOrgVta
                        orderby o.DES_ORG_VTA
                        select o;
                list = q.ToList();
            }
            catch
            {
                list = null;
            }

            return list;
        }
    }
}
